package com.mvp.presenter.impl;

import com.mvp.presenter.MvpPresenter;
import com.mvp.view.MvpView;

import java.lang.ref.WeakReference;

/**
 * Created by dong on 2016/12/1.
 * 中介类
 */
public abstract class MvpBasePresenter<V extends MvpView> implements MvpPresenter<V> {

    private WeakReference<V> view;

    @Override
    public void attachView(V view) {
        //弱引用，防止内存泄露
        this.view = new WeakReference<V>(view);
    }

    @Override
    public void detachView() {
        if (view != null) {
            view.clear();
            view = null;
        }
    }
}
